import { ENUM_CLIP, ENUM_UI } from "../GbzEnum";
import GbzInstance from "../GbzInstance";
import GbzAudioManager from "../manager/GbzAudioManager";
import GbzSdkManager from "../manager/GbzSdkManager";
import GbzToastManager from "../manager/GbzToastManager";
import BaseLayer from "./GbzBaselayer";

const { ccclass, property } = cc._decorator;

@ccclass
export default class GbzRankLayer extends BaseLayer {

    panel: cc.Node = null
    btn_close: cc.Node = null
    // btn_share: cc.Node = null
    btn_solid: cc.Node = null

    onLoad() {
        this.panel = cc.find('style/panel', this.node)
        this.btn_solid = cc.find('btn_solid', this.panel)
        this.btn_solid.on('click', this.onSide, this)
        this.btn_close = cc.find('btn_close', this.panel)
        this.btn_close.on('click', this.onClose, this)
        // this.btn_share = cc.find('btn_share', this.panel)
        // this.btn_share.on('click', this.onShare, this)
    }

    onDestroy() {
        this.btn_close.off('click', this.onClose, this)
        // this.btn_share.off('click', this.onShare, this)
    }

    onEnable() {
        this.zoom(this.panel)
        GbzSdkManager.ins.getRank()
        GbzSdkManager.ins.showInter()
        GbzSdkManager.ins.showBanner(true)
    }

    onDisable() {
        GbzSdkManager.ins.showBanner(false)
    }
    onSide(){
        tt.navigateToScene({
            scene: "sidebar",
            success: (res) => {
                this.onClose()
            },
            fail: (res) => {
                this.onClose()
            },
        });
    }

    onClose() {
        GbzAudioManager.ins.play(ENUM_CLIP.GAME_CLICK)
        GbzInstance.uiMgr.toggle(ENUM_UI.LAYER_RANK, false)
        GbzInstance.uiMgr.toggle(ENUM_UI.LAYER_MENU)
    }

    onShare() {
        GbzAudioManager.ins.play(ENUM_CLIP.GAME_CLICK)
        if (GbzSdkManager.ins.platform()) {
            GbzSdkManager.ins.activeShare()
        } else {
            GbzToastManager.ins.show('仅支持小游戏平台', { gravity: 'TOP', bg_color: cc.color(102, 202, 28, 255) })
        }
    }
}
